/***
* Class Name: iFulfillMoveNextControllerTest
* Author: Accenture       Date: 13-Jun-2011
* Requirement/Project Name: iFULFILL
* Requirement/Project Description: Test coverage class for Move Next controller and 
* Bibhu Mishra          v1.0   dt                  Draft version
* Bhumika Udani         v1.1   dt                  Improvised for code coverage
* Bhumika Udani         v2.0   dt 30 December 2011 Including coverage for ifulfillNewCustomQueryController
*
**/

@isTest

Private class iFulfillMoveNextControllerTest{


    static testMethod void test_Next(){
       
       List<Sobject>  sobjList = new List <Sobject>();
       Profile p = [select id from profile where name='System Administrator'];
       User u1 = new User(alias = 'MoveNex', email='MoveNextsystemadmin@accenture.com',emailencodingkey='UTF-8', lastname='Controller', languagelocalekey='en_US',localesidkey='en_US', profileid = p.Id,timezonesidkey='Asia/Calcutta', username='ifulfillNexttestad@testorg.com');                   
       User u2 = new User(alias = 'workflow', email='coorsystemadmin@accenture.com',emailencodingkey='UTF-8', lastname='Coordinator', languagelocalekey='en_US',localesidkey='en_US', profileid = p.Id,timezonesidkey='Asia/Calcutta', username='workflowCoord@testorg.com');                    
       sobjList.add(u1);
       sobjList.add(u2);

       Insert sobjList;
       sobjList.clear();
       
       //Create Workflow definition
       Workflow_definition__c wfd = new Workflow_definition__c();
       wfd.Status__c = 'Active';
       wfd.Workflow_Name__c = 'WF';
       insert wfd;
           
       //Create Assignment group    
       Assignment_Group_Name__c AGN = new Assignment_Group_Name__c();
       AGN.name = 'Administrator';
       AGN.Type__c = 'Fulfillment';
       insert AGN;                   
               
       //add Function1 to the Wf Definition      
       Workflow_Stage__c WFS = new Workflow_Stage__c();
       WFS.Name = 'Advertiser Approval';
       WFS.Workflow_Code__c = wfd.id;
       WFS.Sequence__c = 1;
 
       sobjList.add(WFS);
           

       //add Function 2 to the Wf Definition      
       Workflow_Stage__c WFS1 = new Workflow_Stage__c();
       WFS1.Name = 'Advertiser Approval';
       WFS1.Workflow_Code__c = wfd.id;
       WFS1.Sequence__c = 2;

       
       sobjList.add(WFS1);
         Insert sobjList;
       sobjList.clear();

      //Assign assignment group to the function1     
       WF_Assignment_Group__c AG = new WF_Assignment_Group__c();            
       AG.Name = 'Administrator';
       AG.Workflow_Function__c = WFS.id;
       AG.AG_Definition__c=AGN.id;
      
       sobjList.add(AG);
       //Assign assignment group to the function2
       WF_Assignment_Group__c AG2 = new WF_Assignment_Group__c();            
       AG2.Name = '2 Administrator';
       AG2.Workflow_Function__c = WFS1.id;
       AG2.AG_Definition__c=AGN.id;
    
        sobjList.add(AG2);
         Insert sobjList;
       sobjList.clear();
            
       //Add Task 1 to function 1      
       Wokflow_Steps__c wfSteps = new Wokflow_Steps__c();
       wfSteps.name = 'Final Verification';
       wfSteps.Wokflow_Stage_Name__c = WFS.id;
       wfSteps.Sequence__c=1;
       wfSteps.Target_Days__c = 2;
       sobjList.add(wfSteps );
       
       //Add Task 1 to Function 2     
       Wokflow_Steps__c wfSteps1 = new Wokflow_Steps__c();
       wfSteps1.name = 'Final Verification';
       wfSteps1.Wokflow_Stage_Name__c = WFS1.id;
       //wfSteps1.Default_Assignment_Group__c = 'Adminstrator';
       wfSteps1.Target_Days__c = 12;
       wfSteps1.Sequence__c = 1;
       sobjList.add(wfSteps1 );
       Insert sobjList;
       sobjList.clear();
              
     
       Fullfilment_Item__c FI = new Fullfilment_Item__c();
       FI.Current_Stage__c = WFS.id;
       FI.Workflow_Code__c = wfd.id;
       FI.Current_Step__c = wfSteps.id;
       FI.ownerID = u1.id;
       FI.Previous_Task__c = wfSteps.name;
       FI.Previous_Task_Sequence__c = wfSteps.Sequence__c;
       FI.Previous_Function__c = WFS.name;
       FI.Previous_Function_Sequence__c = WFS.Sequence__c;                        
       insert FI;          
        
        // Initialize the controller           
        ApexPages.StandardController StdCtrl = new ApexPages.StandardController(FI);
        iFulfillMoveNextController controller = new iFulfillMoveNextController(StdCtrl); 
        
        controller.fItem.Current_Stage__r= WFS; 
        controller.fItem.Current_Step__r = wfSteps;         
        update controller.fItem;      
        
        //call each method of controller 
        Test.StartTest();
        controller.dummy();
        controller.immediateNextFunction();
        controller.skipFunction();
        controller.getselReason();
        controller.nextTask();
        controller.updateFitem();
        controller.isUserPartOfNextAssignmentGroup();
        controller.nextFunctionAssingmentGroup();
        //controller.intilizeAssignmentGroup();
        controller.reArrangeAssignmentGroup();                
        wfSteps.Is_Last_Task__c=true;

        update wfSteps;
        
        controller.skip= true;
        controller.immediateNextFunction();
        controller.skip= true;
        controller.skipFunction();
        controller.stype ='Skip';
        controller.updateFitem();         
        Test.StopTest();
        
            
      }  
    }